package com.allscore.mongo.demo.controller;

import com.allscore.mongo.demo.entity.UserInfo;
import com.allscore.mongo.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 类描述信息
 *
 * @author: <a href="mailto:hu.shidang@allscore.com">胡世党</a><br>
 * @date: 2019/8/14 9:49<br>
 * @copyright: 2019 www.allscore.com Inc. All rights reserved.<br>
 * @changes 重要修改说明(格式 ： 时间 - 修改人 ： 修改内容)<br>
 */
@RestController
public class UserController {

    @Autowired
    private UserRepository userRepository;

    @GetMapping("save")
    public String save() {
        UserInfo userInfo = new UserInfo(System.currentTimeMillis(), "用户" + System.currentTimeMillis(), "123");
        userRepository.save(userInfo);
        return "success";
    }


    @GetMapping("getUserList")
    public List<UserInfo> getUserList() {
        List<UserInfo> userInfoList = userRepository.findAll();
        return userInfoList;
    }

    @GetMapping("delete")
    public String delete(Long id) {
        userRepository.delete(id);
        return "success";
    }

    @GetMapping("update")
    public String update(Long id, String username, String password) {
        UserInfo userInfo = new UserInfo(id, username, password);
        userRepository.save(userInfo);
        return "success";
    }


}
